<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html>
 <head>
    <title>成品物料管理</title>
    <!-- import css and js -->
	<%@ include file="/common/meta.jsp" %>
	<script src="${ctx}/js/ligerUI/js/plugins/ligerLayout.js" type="text/javascript"></script>
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript">
		var basic_Url="${ctx}/yd/basic/materialsEndProduct";
//		var basic_Url1="${ctx}/yd/basic/matertype";
		var basic_WUrl="yd/basic/matertype";
		var basic_Title="添加";
		var show_Width=320;
		var show_Hight=150;
		var pid = null;
		var flag = true;
		function createSearch(){
			init(1,8,'100,100,100,100','20%');

			//第一行的数据
			addCommon(0,0,"lable","名称：");
			addCommon(0,1,"txtlike","name");
			addCommon(0,2,"lable","编码：");
			addCommon(0,3,"txtlike","code");
			addCommon(0,4,"lable","类型：");
			addCommon(0,5,"txtlike","itmetype");
			addCommon(0,6,"lable","规格型号：");
			addCommon(0,7,"txtlike","spec");
		}
		
		function searchAP(){
			if(pid == null){
				multipleSearch("#table1",true,"",basic_Url+"/list.do");
			}else{
			multipleSearch("#table1",true,"",basic_Url+"/list.do?pid="+pid);

			}
		}
		
		
		function gettreeData() 
		 {    
			var manager = null;
			manager = $("#tree1").ligerGetTreeManager(); 
			manager.clear();
//	        manager.loadData(null, basic_Url1+'/tree.do');
	        manager.loadData(null, basic_Url+'/tree.do');
	        manager.collapseAll();
		 }
		
		jQuery(document).ready(function() {
			//创建JQGRID表格
			var grid = $("#table1").ligerGrid({
		        columns: [
		                  { display: '成品物料编码', name: 'code', width: 110 },
		                  { display: '成品物料名称', name: 'name', width: 110 },
		                  { display: '成品物料类型', name: 'itmetype', width: 1,hide:1 },
		                  { display: '封装类型', name: 'packageType', width: 145 },
		                  { display: '型号', name: 'spec', width: 200 },
		                  { display: '客户简码', name: 'customerId', width: 75 },
		                  { display: '创建时间', name: 'dctime', width: 85,
		                	  render: function (item){
		                		  var cdate=new Date(item.dctime);
		                		  return formatDate(cdate,"yyyy-MM-dd");
		                	  }
		                  },
		                  { display: '备注', name: 'remark', width: 140 }
		                      ],  usePager: true,pageSize:15,pageSizeOptions :[15,25,35],enabledSort:false,
		                      width: "100%", height:"92%", checkbox: true,      
		                      onDblClickRow : function (data, rowindex, rowobj){
		                    	  edititem(data);
		                       },
		                      toolbar: { items: [
												  { text: '增加材料', click: additem, icon: 'add' },
												  { line: true },
		                                          { text: '修改', click: getSelected, icon: 'modify' },
		                                          { line: true },
		                                          { text: '删除', click: del, img: '../../../js/ligerUI/skins/icons/delete.gif' },
		                                          { line: true },
		                                          { text: '导出', click: exportExcel, img: '${ctx}/images/excel.gif' }
		                                          ]
		                                          }
		                  });
			$("#pageloading").hide();
			
			
			$("#layout1").ligerLayout({ leftWidth: 200,height: '100%',heightDiff:-24,space:4});
			var actionNodeID=null;
			 
			
			$("#tree1").ligerTree({  
//				 url: basic_Url1+'/tree.do',
				 url: basic_Url+'/tree.do',
				 nodeWidth: 115,
				 checkbox: false,
		         slide: false,
		         onClick:function(node){
		        	 actionNodeID = node.data.id;
// 		        	 alert("asdasda:"+node.data.jd);
		        	 if(node.data.jd >= 2){
		        		 flag = false;
		        	//	 multipleSearch("#table1",true,"",basic_Url+"/list.do?ID="+node.data.id);
		        	 }else{
		        		 flag = true;
		        	 }
		        	 multipleSearch("#table1",true,"",basic_Url+"/list.do?ID="+node.data.id);
		         }
		     });
			
			 
			 //添加物料
			 function additem(){
				 if(actionNodeID == null || actionNodeID.length<=0){
					 $.dialog.alert("请选择需要添加的类型!");
					 return false;
				 }
				 if(flag){
					 $.dialog.alert("请选择二级以下的类型!");
					 return false;
				 }
					var url = "yd/basic/materialsEndProduct/operate/add/"+actionNodeID+".do";
					ShowIframeDialog("operate","添加物料",url,320,300);
			 }
			 
			//修改物料
			 function edititem(data){
					 /* if(flag){
						 $.dialog.alert("请选择二级以下的类型!");
						 return false;
					 } */
					var url = "yd/basic/materialsEndProduct/operate/edit/"+data.id+".do";
					ShowIframeDialog("operate","修改物料",url,320,300);
			 }
			 
			//修改物料
			 function getSelected(){
				/*  if(flag){
					 $.dialog.alert("请选择二级以下的类型!");
					 return false;
				 } */
				 var grid = $("#table1").ligerGetGridManager(); 
					var rows = grid.getCheckedRows();
					var data =grid.getSelectedRow();
					if(rows.length==0){
						$.dialog.alert("请选择一行数据!");
						return false;
					}else{
						edititem(data);
					}
			}
			
			//导出物料
				function exportExcel(){
				   	var filtersStr = generateCondition();
				   	if(actionNodeID==null){
				   		$.dialog.confirm("您没有选择物料类型！是否导出符合条件的材料！",function(){
							var path = basic_Url+"/exportExcel.do?filters="+filtersStr+"&_search=true";
						   	window.open(path,"_blank");
				   		});
				   	}
				   	if(actionNodeID!=null){
				   		$.dialog.confirm("是否导出当前选择类型的物料！如果需导出全部物料请刷新当前页！",function(){
				   			var path = basic_Url+"/exportExcel.do?filters="+filtersStr+"&_search=true&ID="+actionNodeID;
						   	window.open(path,"_blank");
				   		});
				   	}
				}
			 
		});
		
	</script>
	
  </head>
 <body style="padding:10px" onLoad="createSearch()">  
       <div id="pageHeader" class="pageHeader">
               <div class="searchBar" id="multipleSearchDialog">
	                <table class="table" width="100%" id="searchHeader" >  
                        <tbody id="newbody">
                        </tbody>
 	                </table>
                    <div class="subBar">
			             <ul>
				             <li><div class="buttonActive"><div class="buttonContent"><button type="submit" id="btnSearch" onclick="searchAP()">查询</button></div></div></li>
				             <li><a class="button" onclick="clearSearch()"><span>重置</span></a></li>
			             </ul>
	                </div>
               </div>
          </div>
      <div id="layout1">
            <div position="left" title="物料分类信息">
            <div style="width:100%; height:380px; float:left;overflow:auto;  ">
   				 <ul id="tree1"></ul>
    		</div> 
            </div>
            <div position="center" title="成品物料列表" id="table1">
            
            </div>  
        </div> 
    </body>
</html>